<?php
namespace app\index\controller;

use think\Controller;
use think\View;
use Jssdk\JSSDK;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/1
 * Time: 10:20
 */
class Order extends CheckMember{

    /**
     * 确认订单
     * @return \think\response\Json
     */
    public function affirm_order() {
        $param = input('param.');
        $param['address_id'] = input('param.address_id', 0);
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('affirm_order', $param);
        $this->assign('data', $data['data']);

        $this->assign('request', input('param.request', ''));
        return view();
    }

    /**
     * 创建订单
     * @return \think\response\Json
     */
    public function create_order() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('create_order', $param);
        return json($data);
    }

    /**
     * 订单列表
     * @return \think\response\View
     */
    public function index(){
        if (request()->isAjax()) {
            $param['member_id'] = session('member_id');
            $data = $this->local_invoke_api('get_member_order_list', $param);
            $view = new View();
            $view->assign('data', $data['data']);
            $tpl = $view->fetch('index_tpl');
            $data['tpl'] = $tpl;
            return json($data);
        } else {
            return view();
        }
    }

    /**
     * 订单详情
     * @return \think\response\View
     */
    public function info(){
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_order_info', $param);
        $this->assign('data', $data['data']);
        return view();
    }

    /**
     * 收银台
     * @return \think\response\View
     */
    public function pay() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_pay_info', $param);
        $this->assign('data', $data['data']);
        return view();
    }

    /**
     * 取消订单
     * @return \think\response\View
     */
    public function cancel_order() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('cancel_order', $param);
        return json($data);
    }

    /**
     * 取消订单
     * @return \think\response\View
     */
    public function back_merchant() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('back_merchant', $param);
        return json($data);
    }

    /**
     * 取消订单
     * @return \think\response\View
     */
    public function confirm_receipt() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('confirm_receipt', $param);
        return json($data);
    }
}